#ifndef _SRC_NET_HTTP_HTTP_SERVER_H_
#define _SRC_NET_HTTP_HTTP_SERVER_H_

#include <functional>
#include <string_view>

#include "src/base/utils.h"
#include "src/net/tcp_server.h"

namespace fio66::net {
class HttpRequest;
class HttpResponse;

class HttpServer {
 public:
  DISALLOW_COPY_AND_ASSIGN(HttpServer)
  using HttpCallback = std::function<void(const HttpRequest&, HttpResponse*)>;

  HttpServer(EventLoop* loop, const InetAddress& listen_addr,
             std::string_view name,
             TcpServer::Option option = TcpServer::kNoReusePort);

  EventLoop* GetLoop() const;
  void SetHttpCallback(const HttpCallback& cb);
  void SetThreadNum(int num);
  void Start();

  private:
  void OnConnection(const TcpConnectionPtr& conn);
  void OnMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp receive_time);
  void OnRequest(const TcpConnectionPtr&, const HttpRequest&);

  private:
  TcpServer server_;
  HttpCallback callback_;
};

}  // namespace fio66::net

#endif  // _SRC_NET_HTTP_HTTP_SERVER_H_
